Lesson 02
Lesson 02
Data types and control flow
Data types and control flow
These primitives are the building blocks for every script and system you’ll write.
These primitives are the building blocks for every script and system you’ll write.
Numbers and strings
Numbers and strings
# Numbers # Numbers
tax_rate = 0.12 # floattax_rate = 0.12 # float
units = 7 # intunits = 7 # int
total = units * 9.5total = units * 9.5
with_tax = total * (1 + tax_rate)with_tax = total * (1 + tax_rate)
print(with_tax)print(with_tax)
# Strings# Strings
title = "SigLabs"title = "SigLabs"
tagline = f"Welcome to {title}"tagline = f"Welcome to {title}"
print(tagline.upper())print(tagline.upper())
print("abc".replace("b", "x"))print("abc".replace("b", "x"))
Collections
Collections
# Lists (ordered, mutable) # Lists (ordered, mutable)
prices = [10.0, 12.5, 9.9]prices = [10.0, 12.5, 9.9]
prices.append(11.2)prices.append(11.2)
# Tuples (ordered, immutable)# Tuples (ordered, immutable)
point = (3, 4)point = (3, 4)
# Dicts (key-value)# Dicts (key-value)
instrument = {"symbol": "SIG", "price": 12.34}instrument = {"symbol": "SIG", "price": 12.34}
instrument["currency"] = "USD"instrument["currency"] = "USD"
# Sets (unique, unordered)# Sets (unique, unordered)
seen = {"AAPL", "MSFT"}seen = {"AAPL", "MSFT"}
seen.add("GOOG")seen.add("GOOG")
Conditionals
Conditionals
price = 12.5 price = 12.5
if price > 20:if price > 20:
label = "expensive" label = "expensive"
elif price > 10:elif price > 10:
label = "fair" label = "fair"
else:else:
label = "cheap" label = "cheap"
print(label)print(label)
Loops
Loops
# for-loop # for-loop
symbols = ["SIG", "EURUSD", "BTC"]symbols = ["SIG", "EURUSD", "BTC"]
for s in symbols:for s in symbols:
print(s) print(s)
# while-loop# while-loop
count = 3count = 3
while count:while count:
print(count) print(count)
count -= 1 count -= 1
Comprehensions
Comprehensions
# List, dict, set comprehensions # List, dict, set comprehensions
nums = [1, 2, 3, 4, 5]nums = [1, 2, 3, 4, 5]
squares = [n*n for n in nums]squares = [n*n for n in nums]
evens = {n for n in nums if n % 2 == 0}evens = {n for n in nums if n % 2 == 0}
index = {n: i for i, n in enumerate(nums)}index = {n: i for i, n in enumerate(nums)}
print(squares, evens, index)print(squares, evens, index)
Accelerate with SigLabs Financial Software
Accelerate with SigLabs Financial Software
Forecasting, market screening, risk insights, and reporting—built for speed and clarity.
Forecasting, market screening, risk insights, and reporting—built for speed and clarity.
Next steps
Next steps
You’re ready for functions, modules, and venv in Lesson 03.
You’re ready for functions, modules, and venv in Lesson 03.